<template>
  <div class='container'>
    <el-dialog
      title="题目审核"
      :visible="showDialog"
      class="dialog"
      @close="btnCancel"
      width="400px"
    >
      <el-form
        ref="dialog"
        :model="formDate"
        :rules="rules"
      >

        <el-form-item>
          <el-radio
            v-model="formDate.chkState"
            label="1"
          >通过</el-radio>
          <el-radio
            v-model="formDate.chkState"
            label="2"
          >拒绝</el-radio>
        </el-form-item>

        <el-form-item prop="chkRemarks">
          <el-input
            type="textarea"
            placeholder="请输入意见"
            :rows="2"
            v-model="formDate.chkRemarks"
          ></el-input>
        </el-form-item>

      </el-form>
      <el-row
        slot="footer"
        type="flex"
        justify="center"
      >

        <el-button
          type="primary"
          size="small"
          @click="btnOk"
        >确定</el-button>
        <el-button
          size="small"
          @click="btnCancel"
        >取消</el-button>

      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  props: {
    checkId: {
      type: [Number, String],
      required: true
    },
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {

      formDate: {
        chkRemarks: '',
        chkState: 1
      },
      // formDate: {
      //   opinion: '', // 意见
      //   chkTime: '', // 时间
      //   checker: '' // 审核人
      // },
      rules: { chkRemarks: [{ trigger: 'blur', required: true, message: '审核意见不能为空' }] }
    }
  },
  created () {
  },
  methods: {
    async btnOk () {
      try {
        await this.$refs.dialog.validate()
        // console.log(this.checkId)
        // { chkState: this.chkState, id: this.checkId, chkRemarks: this.formDate.chkRemarks }

        const { data } = await choiceCheck({ id: this.checkId, ...this.formDate, chkState: parseInt(this.formDate.chkState) })
        console.log(data)
        this.$message.success('操作成功')
        this.$emit('update:showDialog', false)
        this.$emit('resCheckedQuestionsList', this.formDate)
        this.$emit('getQuestionsList', this.formData)
        this.$emit('getCheQuestionsList', this.formData)
        this.$emit('getCheckedQuestionsList', this.formData)
      } catch (error) {
        console.log(error)
      }
    },
    btnCancel () {
      this.formDate = {
        chkRemarks: '',
        chkState: '1'
      }
      this.$refs.dialog.resetFields()
      this.$emit('update:showDialog', false)
    }
  }
}
</script>

<style scoped lang='scss'>
// .dialog {
//   margin: 0 auto;
//   width: 1000px;
// }
</style>
